<?php if (!defined('SERVER_ROOT')) exit('No direct script access allowed');

class donvi_Controller extends Controller {

    function __construct(){
        parent::__construct('qlcb', 'donvi');
        $this->check_login();
        $this->view->template->menu_html =$this->CREATE_MENU();
        $this->view->template->nhacviec_html =$this->CREATE_NHAC_VIEC(); 
        $this->CHECK_QUYEN('qlcb', 'donvi');
    }

    function main(){
        (Session::get(TIEP_DAU_NGU_SESSION.'QUAN_TRI') == 1) Or die($this->access_denied());
        $this->dsp_all_donvi();
    }
    private function _save_filter(){
        $v_MA_LOAI_DON_VI_filter     = $this->get_post_var('cbx_MA_LOAI_DON_VI_filter');
        $v_MA_DON_VI_CHU_QUAN_filter = $this->get_post_var('cbx_MA_DON_VI_CHU_QUAN_filter');
        return array(
            'cbx_MA_LOAI_DON_VI_filter'     => $v_MA_LOAI_DON_VI_filter,
            'cbx_MA_DON_VI_CHU_QUAN_filter' => $v_MA_DON_VI_CHU_QUAN_filter,
        );
    }
    function dsp_all_donvi(){
        (Session::get(TIEP_DAU_NGU_SESSION.'QUAN_TRI') == 1) Or die($this->access_denied());
        $arr_filter = $this->_save_filter();
        $VIEW_DATA['arr_filter']                  = $arr_filter;
        $VIEW_DATA['arr_all_donvi']               = $this->model->qry_all_donvi_filter($arr_filter);
        $VIEW_DATA['arr_all_loaidonvi_filter']    = $this->model->SELECT_LOAIDONVI_tatca();
        $VIEW_DATA['arr_all_donvichuquan_filter'] = $this->model->SELECT_DONVICHUQUAN_tatca();
        $this->view->render('dsp_all_donvi', $VIEW_DATA);
    }
    public function dsp_single_donvi($MA_DON_VI){
        (Session::get(TIEP_DAU_NGU_SESSION.'QUAN_TRI') == 1) Or die($this->access_denied());
        $MA_DON_VI = replace_bad_char($MA_DON_VI);
        $VIEW_DATA['arr_single_donvi'] = $this->model->qry_single_donvi($MA_DON_VI);
        $VIEW_DATA['arr_all_loaidonvi'] = $this->model->SELECT_LOAIDONVI_nothing();
        $VIEW_DATA['arr_all_donvichuquan'] = $this->model->SELECT_DONVICHUQUAN_chon();
        $this->view->render('dsp_single_donvi', $VIEW_DATA);
    }
    public function update_donvi(){
        (Session::get(TIEP_DAU_NGU_SESSION.'QUAN_TRI') == 1) Or die($this->access_denied());
        $this->model->goback_url = $this->view->get_controller_url() . 'dsp_all_donvi';
        $this->model->update_donvi();
    }
    public function delete_donvi(){
        (Session::get(TIEP_DAU_NGU_SESSION.'QUAN_TRI') == 1) Or die($this->access_denied());
        $this->model->goback_url = $this->view->get_controller_url() . 'dsp_all_donvi';
        $this->model->delete_donvi();
    }
    
}